package com.yn.common.enums;

import lombok.Getter;

/**
 * 业务类型枚举
 * 对应数据库 business_type 字段：0-普通预约 1-急诊预约 2-机构预约
 */
@Getter
public enum BusinessTypeEnum {

    NORMAL_APPT(0, "普通预约"),
    EMERGENCY_APPT(1, "急诊预约"),
    INSTITUTION_APPT(2, "机构预约");

    private final Integer code;
    private final String name;

    BusinessTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据 code 获取枚举实例
     * @param code 业务类型编码
     * @return 对应的枚举，无匹配返回 null
     */
    public static BusinessTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (BusinessTypeEnum typeEnum : BusinessTypeEnum.values()) {
            if (typeEnum.getCode().equals(code)) {
                return typeEnum;
            }
        }
        return null;
    }
}